Feature: The user can edit nodes according to their types and save the result

  Background: I have an XML file opened with sample data for all node types
    Given a file named "example.xml" with:
    """
    <?xml version="qwe" encoding="asd"?>
    <root>
      <!--comment-->
      plain text1
      plain text2
      <el1/>
      <elemenwithchildren key1="value1" key2="value2">
        <child1/>
        <child2/>
      </elemenwithchildren>
    </root>
    """
    When I launch XML Editor interactively
    And I type "1"
    And I type "example.xml"
    And I type "2"

  @editnode
  Scenario: When I edit a comment I get a corresponding dialog and a success message
    When I type "5,0,hello" in succession
    Then the cursor should be `~~> <!--hello-->`
    And the output should contain:
    """
    ~ current content of the comment node:
    <!--comment-->

    ! Warning every character not including A-Za-z0-9_-., will be removed.
    ~ Please enter new content:
    """
    And the output should contain:
    """
    ~ comment node successfully changed!
    ~ updated content of the comment node:
    <!--hello-->
    """

  @editnode
  Scenario: When I edit a plain text node I get a corresponding dialog and a success message
    When I type "5,5,0,ruzenka" in succession
    Then the cursor should be `~~> ruzenka`
    And the output should contain:
    """
    ~ current content of plain text node:
    plain text1

    ! Warning every character not including A-Za-z0-9_-., will be removed.
    ~ Please enter new content:
    """
    And the output should contain:
    """
    ~ plain text node successfully changed!
    ~ updated content of plain text node:
    ruzenka
    """

  @editnode
  Scenario: When I edit an element node name I get a corresponding dialog and a success message
    When I type "0,0,hello" in succession
    Then the cursor should be `~~> <hello>`
    And the output should contain:
    """
    ~ current content of the element node:
    <root>
       ...
    """
    And the output should contain:
    """
    (0) element name: root
    (n) insert new attribute
    ! Choose what to edit or delete (0..0):
    """
    And the output should contain:
    """
    ~ updated content of the element node:
    <hello>
       ...
    """

  @editnode
  Scenario: When I edit an element node attribute I get a corresponding dialog and a success message
    When I type "5,5,5,5,5,0,1,kulcs,ertek" in succession
    #And I close the stdin stream
    Then the cursor should be `~~> <elemenwithchildren key2="value2" kulcs="ertek">`
    And the output should contain:
    """
    ~ current content of the element node:
    <elemenwithchildren key1="value1" key2="value2">
       ...
    """
    And the output should contain:
    """
    (0) element name: elemenwithchildren
    (1) key1="value1"
    (2) key2="value2"
    (n) insert new attribute
    ! Choose what to edit or delete (0..2):
    """
    And the output should contain:
    """
    ~ selected attribute: key1="value1"
    ! Warning every character not including A-Za-z0-9_-., will be removed.
    ~ Enter the updated attribute key (empty string to delete):
    """
    And the output should contain:
    """
    ! Warning every character not including A-Za-z0-9_-., will be removed.
    ~ Enter the updated attribute value:
    """
    And the output should contain:
    """
    ~ updated content of the element node:
    <elemenwithchildren key2="value2" kulcs="ertek">
       ...
    """

  @editnode
  Scenario: When I delete an element node attribute I get a corresponding dialog and a success message
    When I type "5,5,5,5,5,0,1, " in succession
    #And I close the stdin stream
    Then the cursor should be `~~> <elemenwithchildren key2="value2">`
    And the output should contain:
    """
    ~ current content of the element node:
    <elemenwithchildren key1="value1" key2="value2">
       ...
    """
    And the output should contain:
    """
    (0) element name: elemenwithchildren
    (1) key1="value1"
    (2) key2="value2"
    (n) insert new attribute
    ! Choose what to edit or delete (0..2):
    """
    And the output should contain:
    """
    ~ selected attribute: key1="value1"
    ! Warning every character not including A-Za-z0-9_-., will be removed.
    ~ Enter the updated attribute key (empty string to delete):
    """
    And the output should contain:
    """
    ~ updated content of the element node:
    <elemenwithchildren key2="value2">
       ...
    """

  @editnode
  Scenario: When I insert an element node attribute I get a corresponding dialog and a success message
    When I type "5,5,5,5,5,0,n,kulcs,ertek" in succession
    #And I close the stdin stream
   Then the cursor should be `~~> <elemenwithchildren key1="value1" key2="value2" kulcs="ertek">`
    And the output should contain:
    """
    ~ current content of the element node:
    <elemenwithchildren key1="value1" key2="value2">
       ...
    """
    And the output should contain:
    """
    (0) element name: elemenwithchildren
    (1) key1="value1"
    (2) key2="value2"
    (n) insert new attribute
    ! Choose what to edit or delete (0..2):
    """
    And the output should contain:
    """
    ! Warning every character not including A-Za-z0-9_-., will be removed.
    ~ Enter the new attribute key (existing keys will be overwritten):
    """
    And the output should contain:
    """
    ! Warning every character not including A-Za-z0-9_-., will be removed.
    ~ Enter the new attribute value:
    """
    And the output should contain:
    """
    ~ updated content of the element node:
    <elemenwithchildren key1="value1" key2="value2" kulcs="ertek">
       ...
    """
